﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KVB.Common;
using Customer_Profile.eCard.DBDao;

namespace Customer_Profile.eCard
{
    public partial class dealSearchLish : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Comm.BindDll(ref dropTerm, "TermType", true, "");
                Comm.BindDll(ref dropEntity, "Entity", true, "");
            }
            bindGrid();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {

        }

        private void bindGrid()
        {
           
            try
            {
                DataSet ds = DealDao.getDeals();
                if (ds != null && ds.Tables.Count > 0)
                {
                    GvData.DataSource = ds.Tables[0];
                    GvData.DataBind();
                }
                else
                {
                    GvData.DataBind();
                }
            }
            catch (Exception ex)
            {
                Log.WriteDefaultLog("bindGrid", ex.ToString());
            }
        }

        protected void GvData_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GvData.PageIndex = e.NewPageIndex;
            bindGrid();
        }

        protected void GvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {

                if (e.Row.RowType == DataControlRowType.DataRow)
                {                    
                    LinkButton lb = (LinkButton)e.Row.Cells[0].Controls[1];
                    lb.Attributes.Add("onclick", "javascript:window.open('CardDetail.aspx?cardno=" + lb.Text + "');return false");

                    ImageButton ib = (ImageButton)e.Row.Cells[8].Controls[1];
                    ImageButton ibSend = (ImageButton)e.Row.Cells[9].Controls[1];
                    ImageButton ibEdit = (ImageButton)e.Row.Cells[10].Controls[1];

                    ib.Attributes.Add("cardno", lb.Text);
                    ibSend.Attributes.Add("cardno", lb.Text);
                    ibEdit.Attributes.Add("cardno", lb.Text);
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("eCard_input.aspx",true);
        }

        protected void imgbt_Click(object sender, ImageClickEventArgs e)
        {
            string cardno = ((ImageButton)sender).Attributes["cardno"].ToString();
            Response.Redirect("transferSearchList.aspx?CARDNO=" + cardno, true);
        }

        protected void imgbtsend_Click(object sender, ImageClickEventArgs e)
        {
            string cardno = ((ImageButton)sender).Attributes["cardno"].ToString();
            Response.Redirect("cflowSearchList.aspx?CARDNO=" + cardno, true);
        }

        protected void imgbtedit_Click(object sender, ImageClickEventArgs e)
        {
            string cardno = ((ImageButton)sender).Attributes["cardno"].ToString();
            Response.Redirect("dealEdit.aspx?CARDNO=" + cardno, true);
        }
    }
}